/*     */ package com.infoservice.schedule.generator;
/*     */ 
/*     */ import com.infoservice.po3.POFactory;
/*     */ import com.infoservice.po3.POFactoryBuilder;
/*     */ import com.infoservice.po3.core.context.POContext;
/*     */ import com.infoservice.po3.core.exceptions.DAOException;
/*     */ import com.infoservice.schedule.Constant;
/*     */ import com.infoservice.schedule.po.pos.TaskPO;
/*     */ import com.infoservice.schedule.util.TaskUtils;
/*     */ import java.sql.SQLException;
/*     */ import java.text.SimpleDateFormat;
/*     */ import java.util.Calendar;
/*     */ import java.util.Date;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class GenMinTask extends TaskGenerator
/*     */ {
/*  39 */   private Logger logger = Logger.getLogger(GenMinTask.class);
/*     */ 
/*     */   public GenMinTask(TaskPlanInfo tpInfo, TaskPO task) {
/*  42 */     super(tpInfo, task);
/*     */   }
/*     */ 
/*     */   public void run()
/*     */   {
/*  49 */     genTask();
/*     */   }
/*     */ 
/*     */   public void genTask()
/*     */   {
/*  56 */     this.logger.info("taskInfo==============\n" + this.tpInfo.toString());
/*  57 */     Date planStartTime = getNextExcTime();
/*  58 */     if (!TaskUtils.checkTimeRange(planStartTime, this.tpInfo.getPlanStart(), this.tpInfo.getPlanEnd())) {
/*  59 */       this.logger.info("任务不符合条件");
/*  60 */       return;
/*     */     }
/*     */     try {
/*  63 */       POFactory factory = POFactoryBuilder.getInstance();
/*  64 */       TaskPO taskpo = new TaskPO();
/*  65 */       taskpo.setTaskId(this.tpInfo.getTaskId());
/*  66 */       taskpo.setPlanId(this.tpInfo.getPlanId());
/*  67 */       taskpo.setIgnoreFlag(this.tpInfo.getPlanIgnoreFlag());
/*  68 */       taskpo.setMarker(Integer.valueOf(0));
/*  69 */       taskpo.setExecuteType(this.tpInfo.getTaskManual());
/*  70 */       taskpo.setRunType(Integer.valueOf(-1));
/*  71 */       taskpo.setStartTimeout(this.tpInfo.getPlanStartTimeout());
/*  72 */       taskpo.setP1value(this.tpInfo.getP1value());
/*  73 */       taskpo.setP2value(this.tpInfo.getP2value());
/*  74 */       taskpo.setP3value(this.tpInfo.getP3value());
/*  75 */       taskpo.setP4value(this.tpInfo.getP4value());
/*  76 */       taskpo.setP5value(this.tpInfo.getP5value());
/*  77 */       taskpo.setLogId(factory.getLongPK(taskpo));
/*  78 */       taskpo.setLogId(factory.getLongPK(taskpo));
/*  79 */       Date planStartDate = getNextExcTime();
/*  80 */       taskpo.setPlanStartTime(planStartDate);
/*  81 */       factory.insert(taskpo);
/*  82 */       POContext.endTxn(true);
/*  83 */       this.logger.info("任务编号==" + this.tpInfo.getTaskId() + "，计划编号===" + this.tpInfo.getPlanId() + "，类型===" + this.tpInfo.getPlanRepeatType() + "，计划执行时间===" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(planStartTime));
/*  84 */       setTaskPO(planStartDate);
/*     */     } catch (DAOException e) {
/*  86 */       if ((e.getCause() instanceof SQLException)) {
/*  87 */         SQLException sqlE = (SQLException)e.getCause();
/*  88 */         if ((sqlE.getErrorCode() == 1) && (sqlE.getMessage().indexOf("ORA-00001") != -1)) {
/*  89 */           this.logger.error(e.getMessage(), e);
/*     */         }
/*     */       }
/*  92 */       POContext.endTxn(false);
/*     */     } catch (Exception e) {
/*  94 */       this.logger.error(e.getMessage(), e);
/*  95 */       POContext.endTxn(false);
/*     */     } finally {
/*  97 */       POContext.cleanTxn();
/*     */     }
/*     */   }
/*     */ 
/*     */   public Date getNextExcTime()
/*     */   {
/* 106 */     Calendar cur = TaskUtils.getCalendar();
/* 107 */     Date lastPlanExcDate = null;
/* 108 */     if (this.tk != null) {
/* 109 */       lastPlanExcDate = this.tk.getPlanStartTime();
/*     */     } else {
/* 111 */       Calendar start = TaskUtils.getCalendar();
/* 112 */       String[] temp = this.tpInfo.getPlanStart().split(":");
/* 113 */       start.set(11, Integer.parseInt(temp[0]));
/* 114 */       start.set(12, Integer.parseInt(temp[1]));
/* 115 */       lastPlanExcDate = start.getTime();
/* 116 */       Date endDate = getEndDate();
/* 117 */       if ((start.getTimeInMillis() >= endDate.getTime()) && (lastPlanExcDate.getTime() >= cur.getTimeInMillis())) {
/* 118 */         start.setTimeInMillis(start.getTimeInMillis() - 86400000L);
/* 119 */         lastPlanExcDate = start.getTime();
/*     */       }
/* 121 */       if (lastPlanExcDate.getTime() >= cur.getTimeInMillis())
/* 122 */         return lastPlanExcDate;
/*     */     }
/* 124 */     int times = (int)((cur.getTimeInMillis() - lastPlanExcDate.getTime()) / getInterval());
/* 125 */     times++;
/* 126 */     return new Date(lastPlanExcDate.getTime() + getInterval() * times);
/*     */   }
/*     */ 
/*     */   public Date getEndDate()
/*     */   {
/* 134 */     Calendar cur = TaskUtils.getCalendar();
/* 135 */     String[] end = this.tpInfo.getPlanEnd().split(":");
/* 136 */     cur.set(11, Integer.parseInt(end[0]));
/* 137 */     cur.set(12, Integer.parseInt(end[1]));
/*     */ 
/* 142 */     return cur.getTime();
/*     */   }
/*     */ 
/*     */   public Date getStartDate()
/*     */   {
/* 149 */     Calendar cur = TaskUtils.getCalendar();
/* 150 */     String[] end = this.tpInfo.getPlanStart().split(":");
/* 151 */     cur.set(11, Integer.parseInt(end[0]));
/* 152 */     cur.set(12, Integer.parseInt(end[1]));
/* 153 */     return cur.getTime();
/*     */   }
/*     */ 
/*     */   public void fixTask()
/*     */   {
/*     */   }
/*     */ 
/*     */   public long getDelayTime()
/*     */   {
/* 165 */     Date nextTime = getNextExcTime();
/* 166 */     Calendar cur = TaskUtils.getCalendar();
/* 167 */     this.logger.debug("nextTime===" + nextTime.getTime());
/* 168 */     this.logger.debug("curTime====" + cur.getTimeInMillis());
/* 169 */     this.logger.debug("nextTime-curTime===" + (nextTime.getTime() - cur.getTimeInMillis()));
/* 170 */     return nextTime.getTime() - cur.getTimeInMillis() < Constant.TASK_GEN_AHEAD_TIME ? 0L : nextTime.getTime() - cur.getTimeInMillis() - Constant.TASK_GEN_AHEAD_TIME;
/*     */   }
/*     */ 
/*     */   public long getPeriodTime()
/*     */   {
/* 177 */     return getInterval();
/*     */   }
/*     */ 
/*     */   public int getIgnoreTimes()
/*     */   {
/* 186 */     return 0;
/*     */   }
/*     */ 
/*     */   public void setTaskPO(Date planStartTime)
/*     */   {
/* 193 */     if (this.tk == null) {
/* 194 */       this.tk = new TaskPO();
/*     */     }
/* 196 */     this.tk.setPlanStartTime(planStartTime);
/*     */   }
/*     */ 
/*     */   public long getInterval()
/*     */   {
/* 201 */     return this.tpInfo.getTaskInterval().intValue() * 60 * 1000;
/*     */   }
/*     */ }

/* Location:           D:\Workspace\Work\ASMP_DE\lib\frame3\InfoSchedule_1.0.03.jar
 * Qualified Name:     com.infoservice.schedule.generator.GenMinTask
 * JD-Core Version:    0.6.0
 */